Skip to content

interpreting server_mode field (to support Valkey 8+ cluster)#3050

Open
wipiano wants to merge 1 commit intoStackExchange:mainfrom
imobile:experimental-valkey-cluster
Open

interpreting server_mode field (to support Valkey 8+ cluster)#3050
wipiano wants to merge 1 commit intoStackExchange:mainfrom
imobile:experimental-valkey-cluster

Conversation

@wipiano
Copy link
Copy Markdown

@wipiano wipiano commented Apr 3, 2026

Since Valkey 8, the redis_mode field in the INFO server response has been renamed to server_mode.

This causes StackExchange.Redis to misidentify a Valkey Cluster as running in standalone mode, resulting in incorrect behavior.

As a current workaround, setting extended-redis-compatibility yes on the Valkey server side preserves the redis_mode field in the INFO server response. However, this configuration option may be removed in a future version.

This change adds support for interpreting the server_mode field in the same way as the redis_mode field.

@wipiano wipiano changed the title support server_mode field (to support Valkey 8+ cluster) interpreting server_mode field (to support Valkey 8+ cluster) Apr 3, 2026
@wipiano wipiano force-pushed the experimental-valkey-cluster branch from aa15182 to 241da1a Compare April 3, 2026 02:54
@mgravell
Copy link
Copy Markdown
Collaborator

mgravell commented Apr 6, 2026

I tried to add a unit test to validate this, but I don't have access on the remote; any chance you can enable that, so I can contribute this? Alternatively, the patch I have can be summarized as:

using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace StackExchange.Redis.Tests;

public class ValkeyUnitTests(ITestOutputHelper log)
{
    [Theory]
    [InlineData(ServerType.Standalone)]
    [InlineData(ServerType.Cluster)]
    public async Task IdentifyValkeyCluster(ServerType type)
    {
        using InProcessValkeyLikeServer server = new(log) { ServerType = type };
        await using var client = await server.ConnectAsync();
        var serverApi = client.GetServer(server.DefaultEndPoint);
        Assert.Equal(type, serverApi.ServerType);
        Assert.Equal(ProductVariant.Valkey, serverApi.GetProductVariant(out var version));
        Assert.Equal("8.1",  version);
    }

    private sealed class InProcessValkeyLikeServer(ITestOutputHelper log) : InProcessTestServer(log)
    {
        // see https://github.com/StackExchange/StackExchange.Redis/pull/3050
        protected override string ServerModeKey => "server_mode";

        protected override void Info(StringBuilder sb, string section)
        {
            base.Info(sb, section);
            if (section is "Server")
            {
                sb.AppendLine("valkey_version:8.1")
                    .AppendLine("server_name:valkey");
            }
        }
    }
}

with corresponding changes to InProcessTestServer:

        private string ServerModeValue => ServerType switch
        {
            ServerType.Cluster => "cluster",
            ServerType.Sentinel => "sentinel",
            _ => "standalone",
        };

        protected virtual string ServerModeKey => "redis_mode";

...

            case "Server":
                    AddHeader().Append("redis_version:").AppendLine(VersionString)
                        .Append(ServerModeKey).Append(':').Append(ServerModeValue).AppendLine()
                        .Append("os:").Append(Environment.OSVersion).AppendLine()
                        .Append("arch_bits:x").Append(IntPtr.Size * 8).AppendLine();

...

        span[9] = TypedRedisValue.BulkString(ServerModeValue);

@wipiano
Copy link
Copy Markdown
Author

wipiano commented Apr 6, 2026

Thank you for the review! Since the fork is org-owned, I've temporarily added you as a collaborator with write access. You should have received on invitation - please check when you get a chance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants